package com.wedjg.concurrency.example.singleton;

import com.wedjg.concurrency.annotations.NotRecommend;
import com.wedjg.concurrency.annotations.NotThreadSafe;
import com.wedjg.concurrency.annotations.ThreadSafe;

/**
 * 懒汉式单例
 * 安全发布对象，但是带来更大的性能开销
 * @author wedjg
 * @version 1.0
 * @date 2019/6/2
 */
@ThreadSafe
@NotRecommend
public class SingletonExample3 {

    private static SingletonExample3 instance = null;

    private SingletonExample3() {
    }

    public static synchronized SingletonExample3 getInstance() {
        if (instance == null) {
            instance = new SingletonExample3();
        }
        return instance;
    }
}
